package com.nageoffer.jobtrain.projects.controller;

import com.nageoffer.jobtrain.common.framework.idempotent.NoSmsFrequentRequest;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import com.nageoffer.jobtrain.projects.dto.req.UserLoginReqDTO;
import com.nageoffer.jobtrain.projects.dto.req.UserSendSmsMessageReqDTO;
import com.nageoffer.jobtrain.projects.dto.resp.UserLoginRespDTO;
import com.nageoffer.jobtrain.projects.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录、注册校验控制层
 * author：唐晨
 */
@RestController
@RequiredArgsConstructor
public class LoginController {
    private final LoginService loginService;

    /**
     * 用户登录、注册发送验证码
     */
    @NoSmsFrequentRequest(keyPrefix = "job-train:user_send_message_key:")
    @PostMapping("/api/job-train/project/user/send-message")
    public Result<Void> sendSmsMessageCode(@RequestBody UserSendSmsMessageReqDTO requestParam) {
        loginService.sendSmsMessageCode(requestParam);
        return Results.success();
    }

    /**
     * 用户登录、注册请求
     */
    @PostMapping("/api/job-train/project/user/login")
    public Result<UserLoginRespDTO> loginUser(@RequestBody UserLoginReqDTO requestParam) {
        return Results.success(loginService.loginUser(requestParam));
    }
}
